#include <QFile>
#include "Event.h"
#include "Events.pb.h"

Event::Event() :
   theId(INVALID_ID),
   theCategory(INVALID),
   theName(),
   theMessage(),
   theTimestamp(QDateTime::currentDateTimeUtc()),
   theParameters(EMPTY_PARAMS)
{
   qRegisterMetaType<Event>();
}

Event::Event(quint32 id,
             QList<QString> parameters) :
   theId(id),
   theCategory(INVALID),
   theName(),
   theMessage(),
   theTimestamp(QDateTime::currentDateTimeUtc()),
   theParameters(parameters)
{
   qRegisterMetaType<Event>();
}

quint32 Event::id() const
{
   return theId;
}

Event::Category Event::category() const
{
   return theCategory;
}

QString Event::name() const
{
   return theName;
}

QString Event::message() const
{
   return theMessage;
}

QDateTime Event::timestamp() const
{
   return theTimestamp;
}

QList<QString> Event::parameters() const
{
   return theParameters;
}

void Event::setId(quint32 id)
{
   theId = id;
}

void Event::setCategory(Category category)
{
   theCategory = category;
}

void Event::setName(QString name)
{
   theName = name;
}

void Event::setMessage(QString message)
{
   theMessage = message;

   foreach(QString param, theParameters)
   {
      theMessage.arg(param);
   }
}

void Event::setParameters(QList<QString> parameters)
{
   theParameters = parameters;
}

QString Event::serializeEvent()
{
   Events::EventGPB event;

   event.set_id(theId);
   event.set_category((Events::EventGPB::Category)theCategory);
   event.set_name(theName.toStdString());
   event.set_message(theMessage.toStdString());
   event.set_timestamp(theTimestamp.toString(TIMESTAMP_FORMAT).toStdString());

   return QString(event.SerializeAsString().c_str());
}
